package com.example.testanimation;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;


import com.example.testanimation.javabean.Courses;

import java.util.ArrayList;
import java.util.List;

public class Class extends AppCompatActivity {
    private ListView mLvClass; // 确保这里与XML中的ListView ID一致
    private com.example.testanimation.MySQLiteOpenHelper1 mySQLiteOpenHelper1;
    private List<String> displayList; // 用于存储显示在ListView上的字符串数据



    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Compiler EdgeToEdge = null;
        EdgeToEdge.enable();
        setContentView(R.layout.activity_class);
        mLvClass = findViewById(R.id.lv_class); // 确保ID匹配
        mySQLiteOpenHelper1 = new com.example.testanimation.MySQLiteOpenHelper1(this);



        // 加载课程数据到ListView
        loadCoursesIntoListView();
    }

    // 加载课程数据到ListView
    private void loadCoursesIntoListView() {
        List<Courses> coursesList = mySQLiteOpenHelper1.getAllCourses(); // 获取所有课程
        displayList = new ArrayList<>();

        for (Courses course : coursesList) { // 将Coru更正为Courses
            // 这里假设您想以某种格式展示课程信息，例如课程名 + 教师名
            String displayText = course.getCourseName() + " - " + course.getTeacherName()+ " - "+course.getLocation() +" - "+course.getTime();
            displayList.add(displayText);
        }

        // 创建并设置Adapter
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, displayList);
        mLvClass.setAdapter(adapter);
    }
    //点击回到同学页面
    public void goto_student(View view)
    {
        Intent intent = new Intent(Class.this, ListStudent.class);
        startActivity(intent);

    }
    public void goto_self_atclass(View view) {
        Intent intent = new Intent(Class.this, com.example.testanimation.Self.class);
        startActivity(intent);
    }


}